﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace Tenebrous_Manor
{
class Menu
    {
        KeyboardState kb_old = Keyboard.GetState();
        public bool selected;
        int choice;
        int num_choices;

        Texture2D blankTexture;
        SpriteFont font;

        String startGame = "Start Game";
        String controls = "Controls";
        String credit = "Credits";
        String quitGame = "Quit Game";

        Color color1 = Color.White;
        Color color2 = Color.White;
        Color color3 = Color.White;
        Color color4 = Color.White;

        public Menu(Texture2D blankTexture, SpriteFont font)
        {
            this.blankTexture = blankTexture;
            this.font = font;

            this.Initialize();
        }

        public void Initialize()
        {
            choice = 0;
            selected = false;
            num_choices = 4;
        }

        public void Update(GameTime gameTime)
        {
            KeyboardState kb = Keyboard.GetState();

            selectedColor();

            if (kb.IsKeyDown(Keys.S) && !kb_old.IsKeyDown(Keys.S))
            {
                if (choice >= num_choices)
                    choice = num_choices - 1;
                else
                    choice++;
            }
            else if (kb.IsKeyDown(Keys.W) && !kb_old.IsKeyDown(Keys.W))
            {
                if (choice - 1 < 0)
                    choice = 0;
                else
                    choice--;
            }
            else if (kb.IsKeyDown(Keys.Enter) && !kb_old.IsKeyDown(Keys.Enter))
                selected = true;

            kb_old = kb;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //float textPosition = (1000 - font.MeasureString(startGame).X) / 2;

            spriteBatch.DrawString(font, startGame, new Vector2(500, 400), color1);
            spriteBatch.DrawString(font, controls, new Vector2(500, 450), color2);
            spriteBatch.DrawString(font, credit, new Vector2(500, 500), color3);
            spriteBatch.DrawString(font, quitGame, new Vector2(500, 550), color4);
        }

        public void selectedColor()
        {
            switch (choice)
            {
                case 0:
                    color1 = Color.Red;
                    color2 = Color.White;
                    color3 = Color.White;
                    color4 = Color.White;
                    break;
                case 1:
                    color1 = Color.White;
                    color2 = Color.Red;
                    color3 = Color.White;
                    color4 = Color.White;
                    break;
                case 2:
                    color1 = Color.White;
                    color2 = Color.White;
                    color3 = Color.Red;
                    color4 = Color.White;
                    break;
                case 3:
                    color1 = Color.White;
                    color2 = Color.White;
                    color3 = Color.White;
                    color4 = Color.Red;
                    break;

            }
        }

        public int getMenuSelection()
        {
            if (choice == 0)
                return 0;
            else if (choice == 1)
                return 1;
            else if (choice == 2)
                return 2;
            else
                return 3;
        }
    }
}

